/*
 * mqrecv.cpp
 *
 *  Created on: Jul 12, 2013
 *      Author: m
 */

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include "MyMessage.h"
#include "NewMessageQueue.h"

#define TEST_MTYPE 1

using namespace ipc;

int main ( int argc, char* argv[] )
{
    char mostrar[10240];
    MyMessage msg;

    MessageQueue<MyMessage> mq = MessageQueue<MyMessage>::get( "/tmp/mychannel", 'h' );

    sprintf( mostrar,
            "MQRCV: "
            "Empieza a leer mensajes!\n" );
    write( fileno(stdout), mostrar, strlen(mostrar) );

    while( true )
    {
        msg = mq.get( TEST_MTYPE );

        sprintf( mostrar,
                "MQRCV: "
                "Recibido mensaje:\n"
                "mtype: %ld\n"
                "data: %c\n",
                msg.mtype, msg.c );
        write( fileno(stdout), mostrar, strlen(mostrar) );
    }

    return 0;
}
